package com.demo.test.tcp;

import java.math.BigInteger;
import java.text.SimpleDateFormat;
import java.time.Instant;
import java.time.ZoneId;  
import java.time.ZonedDateTime;  
import java.time.format.DateTimeFormatter;
import java.util.Date;

public class HexToTimestampConverter {  
  
    public static void main(String[] args) {  
//        String hexTimestamp = "5ca1e0a48f01";
        String hexTimestamp = "018fa4e0a15c";
//        String hexTimestamp = "cc82df9fdd00";
        long timestampMillis = hexStringToLong(hexTimestamp);
//        long timestampMillis = 1716458135900L;

  
        // 使用Instant类，它表示一个瞬间的时间点  
        Instant instant = Instant.ofEpochMilli(timestampMillis);  
  
        // 如果你想要一个可读的日期时间字符串  
        ZonedDateTime zonedDateTime = instant.atZone(ZoneId.of("UTC"));  
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS");  
        String formattedDateTime = zonedDateTime.format(formatter);

        SimpleDateFormat sdfNew = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date date = new Date(timestampMillis);
        String format = sdfNew.format(date);

        System.out.println("UTC Time: " + formattedDateTime);  
    }  
  
    // 将16进制字符串转换为长整型（毫秒时间戳）  
    public static long hexStringToLong(String hex) {  
        return new BigInteger(hex, 16).longValue();  
    }  
}